/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package regulatoryInteractionsStats.yeast;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import utils.FileUtils;

/**
 *
 * @author jamie
 */
public class AlignmentSet {

    private File alignmentSummaryFile = new File("/Users/jamie/Documents/monkeys/alignments/stats.txt");
    private HashMap<String, Double> scores = new HashMap<String, Double>();
    private HashSet<String> genes = new HashSet<String>();
    private YeastGeneLibrary yeastGeneLibrary;

    public AlignmentSet(YeastGeneLibrary ygl) {
        this.yeastGeneLibrary = ygl;
        populateData();
    }

    private void populateData() {
        BufferedReader reader = FileUtils.getBufferedReader(alignmentSummaryFile);
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                String[] split = line.split("\t");
                String[] split2 = split[0].split(":");
                YeastGene yg1 = yeastGeneLibrary.getGeneByAccession(split2[0]);
                YeastGene yg2 = yeastGeneLibrary.getGeneByAccession(split2[1]);
                if(yg1!=null && yg2!=null){
                    String[] symbols = new String[2];
                    symbols[0] = yg1.getSymbol();
                    symbols[1] = yg2.getSymbol();
                    Arrays.sort(symbols);
                    scores.put(symbols[0]+":"+symbols[1], Double.parseDouble(split[2]));
                    if(!genes.contains(symbols[0])){
                        genes.add(symbols[0]);
                    }
                    if(!genes.contains(symbols[1])){
                        genes.add(symbols[1]);
                    }
                }
            }
            reader.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public HashMap<String, Double> getScores() {
        return scores;
    }

    public File getAlignmentSummaryFile() {
        return alignmentSummaryFile;
    }

    public YeastGeneLibrary getGeneLibrary() {
        return yeastGeneLibrary;
    }

    public HashSet<String> getGenes() {
        return genes;
    }



}
